﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.IO;
using System.Web.Script.Serialization;

namespace EasyClass {
	public partial class ExportResultForm : Form {
		Controller controller;
		public ExportResultForm(Controller c, int selectedIndex = -1) {
			InitializeComponent();
			controller = c;
			comboBox1.Items.AddRange(controller.GetAllTasksName());
			if (selectedIndex != -1) comboBox1.SelectedIndex = selectedIndex;
		}
		
		private void button3_Click(object sender, EventArgs e) {
			SaveFileDialog sfd = new SaveFileDialog();
			sfd.Filter = "Txt File(*.txt)|*.txt";
			if (sfd.ShowDialog() == DialogResult.OK) {
				string localFilePath = sfd.FileName.ToString(); //acquire file path
				textBox1.Text = localFilePath;
				if (localFilePath.Substring(localFilePath.Length - 4, 4) != ".txt")
					textBox1.Text += ".txt";
			}
		}

		private void button2_Click(object sender, EventArgs e) {
			Close();
		}

		private void button1_Click(object sender, EventArgs e) {
			if (comboBox1.Text == "") {
				MessageBox.Show("Task not specified");
				return;
			}
			if (textBox1.Text == "") {
				MessageBox.Show("Path not specified");
				return;
			}
			controller.CreateTxtLog(comboBox1.SelectedItem.ToString(), textBox1.Text);
			System.Diagnostics.Process.Start("notepad.exe ", textBox1.Text); 
			Close();
		}

		private void ExportTaskForm_Load(object sender, EventArgs e) {

		}

	}
}
